package com.spring.cloud.examples.service.impl;

import com.spring.cloud.examples.feign.Service2Api;
import com.spring.cloud.examples.mapper.Service1Mapper;
import com.spring.cloud.examples.service.Service1;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.UUID;

@Service
public class Service1Impl implements Service1 {

    @Autowired
    private Service1Mapper service1Mapper;

    @Autowired
    private Service2Api service2Api;

    @GlobalTransactional(name = "service1-insertService1",rollbackFor = Exception.class)
    @Override
    public void insertService1() {
        //保存seata-test1数据库
        service1Mapper.insertService1(UUID.randomUUID().toString());
        //在这里调用service2,保存seata-test2数据库
        service2Api.insertService2();
        //测试回滚
        int i=1/0;
    }
}
